<?php
/**
 * 用户信息管理模型
 * @author e5
 *
 */
class UserInfoModel extends Model{
	public $table = "user";
	public $validate = array(
			array("nickname","nonull","昵称不能为空",2,2),
			array("nickname","_isExt","昵称已存在",2,2),
			array("email","email","邮箱格式不正确",3,2),
			array("address","nonull","地址不能为空",2,2),
			array("phone","phone","手机号格式不正确",2,2),
			array("tel","tel","座机号格式不正确",3,2)
	);
	public $map = array(
			'email'=>'uemail',
			'address'=>'uaddress',
			'phone'=>'uphone',
			'tel'=>'utel'
	);
	/**
	 * 验证昵称是否存在
	 * @param string $name
	 * @param string $value
	 * @param string $msg
	 * @param unknown $arg
	 * @return unknown|boolean
	 */
	public function _isExt($name,$value,$msg,$arg){
		$uid = session("uid");
		if ($this->where("nickname='{$value}' AND uid<>{$uid}")->count() > 0){
			return $msg;
		}
		return true;
	}
	public function editInfo(){
		if (!$this->create()) return false;
		$this->update();
		return true;
	}
}